package com.joejag.mavenstats.server.service;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.joejag.mavenstats.client.dto.ProjectDTO;
import com.joejag.mavenstats.client.service.ProjectsService;
import com.joejag.mavenstats.server.dao.FakeProjectsDao;
import com.joejag.mavenstats.server.dao.ProjectsDao;
import com.joejag.mavenstats.server.xml.MavenProjectReader;

import java.util.List;
import java.util.Map;

public class ProjectsServiceImpl extends RemoteServiceServlet implements ProjectsService
{
  private ProjectsDao projectsDao;

  public ProjectsServiceImpl()
  {
    projectsDao = FakeProjectsDao.instance();
  }

  public Map getProjects()
  {
    return projectsDao.getByTeam();
  }

  public List getTeamNames()
  {
    return projectsDao.getTeamNames();
  }

  public boolean addProject(ProjectDTO project)
  {
    projectsDao.addProject(project);
    return true;
  }

  public void editProject(ProjectDTO edittedProject)
  {
    projectsDao.edit(edittedProject);
  }

  public void deleteProject(ProjectDTO deletedProject)
  {
    projectsDao.delete(deletedProject);
  }

  public List getDependencies(String projectURL)
  {
    return new MavenProjectReader(projectURL).getDependencies();
  }

}